import { Provide} from '@midwayjs/core';
import { Book } from '../../entity/user/book';
import { InjectEntityModel } from '@midwayjs/orm';
import { Repository } from 'typeorm';


@Provide()
export class BookService {

  @InjectEntityModel(Book)
  bookModel:Repository<Book>

  async getbook(ownerid: string):Promise<Book[]>{
    try{
      const result = await this.bookModel.find({
        where: {
          ownerid:ownerid
        }
    })
      console.log("result",result);
      return result
    }catch(err){
      console.log("err",err);
      
    }
  }
  
  async book(book:Book):Promise<Book>{
    try{
      const result = await this.bookModel.save(book);
      console.log("result",result);
      return result
    }catch(err){
      console.log("err",err);
      
    }
  }

  
}
